<?php

// Insert into SC_FORMULA (FORMULA_ID,SEQUENCE,TYPE,CODE,CLASS,DESCRIPTION,START_DATE,END_DATE,PCNT_TAX,LINE_ORDER)
//values (XX,1,'SHIPPING_COST','ShippingFixedPrice','CartWS_Model_FormulaEngine_Formula_ShippingFixedPrice','Costo de envio fijo $10',to_timestamp('16-SEP-09','DD-MON-RR HH.MI.SSXFF AM'),null,1,1000);

class CartWS_Model_FormulaEngine_Formula_ShippingPriceNoItems extends CartWS_Model_FormulaEngine_Formula_Abstract {

    public function execute()
    {

		$rowSet = $this->getProperties();
        if( count( $rowSet )) {
            $i=0;
            $result = array();
            foreach( $rowSet as $row ) {
                $result[$i] = $row->toArray();
                $i++;
            }
        }
        $formulaProperties = $result;
        $result = array();
        foreach( $formulaProperties as $property )
        {
            $result[$property['property']] = $property['value'];
        }
        $formulaProperties = $result;

		// Informacion de las lineas
        $rowSet = $this->getOrderLines();
        $countItems = 0;
        if( count( $rowSet )) {
            $i=0;
            $result = array();
            foreach( $rowSet as $row ) {
                $result[$i] = $row->toArray();
                if ( $result[$i]['line_type'] == $formulaProperties['lineType'] )
                {
                    $countItems = $countItems + $result[$i]['ordered_quantity'];
                }
                $i++;
            }
        }

		if ( $countItems == 0 )
		{
			$this->clearMyAmount();
			return CartWS_Model_FormulaEngine_Formula_Abstract::RET_STOP;
		} else {
			return CartWS_Model_FormulaEngine_Formula_Abstract::RET_CONTINUE;
		}

	}

}
